import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'
import qs from 'qs'

const baseUrl = CommonConfig.reportUrl + '/v1'

const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}

/**
 * 获取日流水报表
 * @param params
 * @returns {Promise<unknown>}
 */
export function getDailyReport (params) {
  const url = `${baseUrl}/workshop_daily_report:page`
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }

  return axiosInstance.get(url, reqData).then(res => {
    return Promise.resolve(res.data)
  })
}

/**
 * 导出报表excel
 * @param data
 * @returns {Promise<unknown>}
 */
export function getDailyReportExport (data) {
  const url = `${baseUrl}/workshop_daily_report/excel:export`

  return axiosInstance.post(url, data).then(res => {
    return Promise.resolve(res)
  })
}

/**
 * 换线报表
 * @param params
 * @returns {Promise<unknown>}
 */
export function getChangeoverReports (params) {
  const url = `${baseUrl}/changeover_reports`
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }

  return axiosInstance.get(url, reqData).then(res => {
    return Promise.resolve(res.data)
  })
}

/**
 * 导出报表excel
 * @param params
 * @returns {Promise<unknown>}
 */
export function getChangeoverReportExport (params) {
  const url = `${baseUrl}/changeover_reports/excel:export`

  return axiosInstance.post(url, params).then(res => {
    return Promise.resolve(res.data)
  })
}
